let baseURL = "https://ggok.top"
// let baseURL = "http://127.0.0.1:19100"

export async function getJson(url, data) {
    return await baseReq(url, "GET", {}, data)
}

export async function postJson(url, data) {
    return await baseReq(url, "POST", null, data)
}

export async function putJson(url, data) {
    return await baseReq(url, "PUT", null, data)
}

export async function deleteJson(url, data) {
    return await baseReq(url, "DELETE", null, data)
}

export async function postForm(url, data) {
    return await baseReq(url, "POST", null, data, {
        'Content-Type': 'multipart/form-data;'
    })
}

export async function baseReq(url, method, params, data = {}, headers = {}) {
    // 参考若依 token 处理未登录401 500提示信息
    // const isToken = (config.headers || {}).isToken === false
    // config.header = config.header || {}
    // if (getToken() && !isToken) {
    //     headers['Authorization'] =  getToken()
    // }
    let [error, res] = await uni.request({
        method: method,
        url: baseURL + url,
        data: data,
        header: headers,
        timeout: 10000
    })
    if (error !== null && error !== undefined) {
        uni.showToast({
            title: JSON.stringify(error),
            icon: 'none',
            duration: 3000
        });
        // toast('后端接口连接异常')
        // reject('后端接口连接异常')
        return
    }
    // if (res.code === 401) {
    //
    // }
    // if (res.code === 500) {
    //
    // }
    return res.data
}
